<?php
/**
 * @license    GNU/GPL
 */

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view');

/**
 * HTML View class for the CommunalMeals Component
 *
 */

class CommunalMealsViewSignUp extends JView
{
	function display($tpl = null)
	{
		global $option, $mainframe;
		
		// Get ids from request
		$groupId = JRequest::getVar('group_id', NULL );
		$eventId = JRequest::getVar('event_id', NULL );
		
		// Get data from model
		$event = CMeals::readEvent($eventId, $groupId);
		$member = CMeals::readMember(CMealsFrontEndUtils::getCurrentMemberId());
		$eventType = CMeals::readEventType($event->type);
		$signUpList = CMeals::readSignUpList($groupId, $eventId, CMealsFrontEndUtils::getCurrentMemberId());
		$categoryList = CMeals::readEventCategoryList($event->type);
		
		// Prepare lists etc.
		$lists = array();
		$participantsByCategory = array();
		foreach ($signUpList as $signUp) {
			$participantsByCategory[$signUp->category] = $signUp->participants;
		}
		$participantsList = array();
		for ($i = 0; $i < 10; $i++) {
			$participantsList[] = array('value' => $i, 'text' => $i);
		}
		$partVarNameArray = array();
		foreach ($categoryList as $category) {
			$partVarName = "part_".$category->id; // names of the html post variables for number of participants in each category
			$partVarNameArray[] = $partVarName;
			$selectedValue = $participantsByCategory[$category->id];
			$lists[$category->id] = JHTML::_('select.genericList', $participantsList, $partVarName, 'class="inputbox"', 'value', 'text', $selectedValue );
		}
		
		// Pass data to template
		$this->assignRef( 'member', $member );
		$this->assignRef( 'eventType', $eventType );
		$this->assignRef( 'event', $event );
		$this->assignRef( 'signUpList', $signUpList );
		$this->assignRef( 'categoryList', $categoryList );
		$this->assignRef( 'lists', $lists );
		$this->assignRef( 'partVarNameArray', $partVarNameArray );
		$this->assignRef( 'option', $option );
		
		parent::display($tpl);
	}
}